package com.example.kleinanzeigengenerator;

import com.example.kleinanzeigengenerator.R;
import com.example.kleinanzeigengenerator.common.Constants;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.Toast;

public class SiteAuswahl extends Activity{
	private CheckBox ebayButton;
	private CheckBox sBButton;
	
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.site_auswahl);
		
		ebayButton = (CheckBox)findViewById(R.id.ebayBox);
		sBButton = (CheckBox)findViewById(R.id.sBBox);
		Button nextPageButton = (Button)findViewById(R.id.weiterVSiteWahl);
		
		ebayButton.setOnClickListener(checkBoxListener);
		sBButton.setOnClickListener(checkBoxListener);
		nextPageButton.setOnClickListener(nextPageListener);
		
	}
	
    // Bundle abspeichern
    @Override
	protected void onSaveInstanceState(Bundle savedInstanceState) {

		savedInstanceState.putBoolean(Constants.EBAY_TAG, ebayButton.isChecked());
		savedInstanceState.putBoolean(Constants.SCHWARZESBRETT_TAG, sBButton.isChecked());
		super.onSaveInstanceState(savedInstanceState);
	}
    
    // Bundle auslesen
    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
    	boolean ebay = false;
    	boolean sB = false;

    	if(savedInstanceState != null) {
    		ebay = savedInstanceState.getBoolean(Constants.EBAY_TAG);
    		sB = savedInstanceState.getBoolean(Constants.SCHWARZESBRETT_TAG);
    	}
    	ebayButton.setSelected(ebay);
    	
    	if (sB == true) {
    		sBButton.isChecked();
    	}
    	else {
    		;
    	}
    	super.onRestoreInstanceState(savedInstanceState);
    }
	
	
	private OnClickListener checkBoxListener = new OnClickListener() {
		
		public void onClick(View v) {
			
			Toast.makeText(SiteAuswahl.this,
					"Ebay: " +ebayButton.isChecked() + "\n"+
					"Schwarzes Brett: " +sBButton.isChecked(),
					Toast.LENGTH_LONG).show();
					
		}
	};
	
	
	private OnClickListener nextPageListener = new OnClickListener() {
		
		public void onClick(View v) {
			Intent nextPageIntent = new Intent(SiteAuswahl.this, KleinanzeigenGenerator.class);
			nextPageIntent.putExtra(Constants.EBAY_TAG, ebayButton.isChecked());
			nextPageIntent.putExtra(Constants.SCHWARZESBRETT_TAG, sBButton.isChecked());
			startActivity(nextPageIntent);
		}
	};

}
